package com.platform.admin.designPattern.statusMachine.enums;

import com.platform.admin.designPattern.statusMachine.BaseStatus;
import com.platform.admin.designPattern.statusMachine.StatusMachine;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum PaymentStatusEnum implements BaseStatus {

    INIT("INIT", "初始化")
    ,PAYING("PAYING","支付中")
    ,PAID("PAID", "支付成功")
    ,FAILED("FAILED","支付失败")
    ;

    /**
     * 状态
     */
    private final String status;

    /**
     * 描述
     */
    private final String desc;

    /**
     * 支付状态机内容
     */
    private static final StatusMachine<PaymentStatusEnum, PaymentEventEnum> STATE_MACHINE = new StatusMachine();

    static {
        STATE_MACHINE.accept(null, PaymentEventEnum.PAY_CREATE, INIT);
        STATE_MACHINE.accept(INIT, PaymentEventEnum.PAY_PROCESS, PAYING);
        STATE_MACHINE.accept(PAYING, PaymentEventEnum.PAY_SUCCESS, PAID);
        STATE_MACHINE.accept(PAYING, PaymentEventEnum.PAY_FAIL, FAILED);
    }

    @ApiOperation(value = "通过源状态和事件，获取目标状态")
    public static PaymentStatusEnum getTargetStatus(PaymentStatusEnum sourceStatus, PaymentEventEnum event) {
        return STATE_MACHINE.getTargetStatus(sourceStatus, event);
    }
}
